﻿<%@ Page Title="" Language="C#" MasterPageFile="~/admin/admin.Master" AutoEventWireup="true"
    Inherits="Wjtour.Web.Admin.role.addedi" %>

<%@ Import Namespace="Wjtour.Domain" %>
<%@ Import Namespace="Wjtour.Common" %>
<%@ Import Namespace="Wjtour.Domain.dto" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="content" runat="server">
    <script type="text/javascript">
        function checkNode(t) {
            classname = $(t).attr('id');
            if ($(t).attr('checked') == true) {
                $('.' + classname).attr('checked', true);
            }
            else {
                $('.' + classname).attr('checked', false);
            }
        }

        $(function () {
            $('.children input').click(function () {
                var node = $(this).attr('node');
                if ($(this).attr('checked') == true) {
                    $('#' + node).attr('checked', true);
                }
                else {
                    var classname = $(this).attr('class');
                    var ok = 1;
                    $('.' + classname).each(function () {
                        if ($(this).attr('checked') == true) {
                            ok = 1;
                            return false;
                        }
                        else {
                            ok = 0;
                        }
                    });
                    if (ok == 0) {
                        $('#' + node).attr('checked', false);
                    }
                }
            });
        })

        function getChecked() {
            var ids = [];
            $("#addeditable input[type='checkbox'][checked='true']").each(function () {
                ids.push($(this).val());
            });
            $("#<%=rights.ClientID %>").val(ids.join(','));
        }
    </script>
    <table id="addeditable" border="1" cellpadding="0" cellspacing="0" bordercolor="#dddddd">
        <tr>
            <td width="115px" align="right">
                名称：
            </td>
            <td>
                &nbsp;<asp:TextBox ID="title" runat="server" />
                <asp:HiddenField ID="rights" runat="server" />
            </td>
        </tr>
        <tr>
            <td align="right">
                菜单：
            </td>
            <td style="padding-left: 5px">
                <%
                    foreach (var pitem in menus.Where(m => m.parent_id == 0).ToList())
                    {
                        string pchecked = "";
                        if (pitem.accessid > 0)
                            pchecked = "checked='true'";
                %>
                <div>
                    <label>
                        <input type="checkbox" id="<%=pitem.node %>" name="ids" value="<%=pitem.id %>"
                            <%=pchecked %> onclick='javascript:checkNode($(this));' />&nbsp; <span
                                style="font-size: 12px; font-family: wingdings">1</span>&nbsp;<%=pitem.title %>
                    </label>
                </div>
                <%
                    foreach (var subitem in menus.Where(m => m.parent_id == pitem.id).ToList())
                    {
                        string schecked = "";
                        if (subitem.accessid > 0)
                            schecked = "checked='true'";
                %>
                <div style="line-height: 28px">
                    <label class="children">
                        └─<input node="<%=subitem.node %>" class="<%=subitem.node %>" type="checkbox" name="ids"
                            value="<%=subitem.id %>" <%=schecked %> />&nbsp;<span style="font-size: 12px;
                                font-family: wingdings">2</span>&nbsp;<%=subitem.title %>(模块：<%=subitem.mod %>
                        行为：<%=subitem.act %>)
                    </label>
                </div>
                <%
                    }
                }
                %>
            </td>
        </tr>
        <tr>
            <td align="right">
                &nbsp;
            </td>
            <td>
                &nbsp;<asp:Button ID="submit" CssClass="sub" Text=" 保 存 " runat="server" OnClientClick="return getChecked()"/>
            </td>
        </tr>
    </table>
</asp:Content>
